﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate;
using Entities;
using RepositoriesInterfaces;
using NHibernate.Criterion;
using NHibernate.Linq;

namespace Repositories
{
    public class AllocationRepository : BaseRepository<Allocation>, IAllocationRepository
    {
        public AllocationRepository(ISession session)
        {
            this._session = session;
        }
               
        public IEnumerable<Allocation> GetByDepartmentId(int DepartmentId)
        {
            _session.BeginTransaction();

            IList<Allocation> tmp = (from s in _session.Query<Allocation>()
                                     from x in s.StudyPlanItems
                                     where x.Department.Id == DepartmentId
                                     select s).Distinct().ToList();

            _session.Transaction.Commit();

            return tmp;
        }
    }
}